package b.i.k;

import android.os.Build.VERSION;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.View;
import b.i.k.o.d;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.WeakHashMap;

/* compiled from: KeyEventDispatcher */
public class e {
    public static boolean a = false;
    public static Method b = null;
    public static boolean c = false;
    public static Field d;

    /* compiled from: KeyEventDispatcher */
    public interface a {
        boolean e(KeyEvent keyEvent);
    }

    public static boolean a(View view, KeyEvent keyEvent) {
        WeakHashMap weakHashMap = o.a;
        if (VERSION.SDK_INT < 28) {
            ArrayList arrayList = d.d;
            d dVar = (d) view.getTag(2131297024);
            if (dVar == null) {
                dVar = new d();
                view.setTag(2131297024, dVar);
            }
            WeakReference weakReference = dVar.c;
            if (weakReference == null || weakReference.get() != keyEvent) {
                dVar.c = new WeakReference(keyEvent);
                weakReference = null;
                if (dVar.b == null) {
                    dVar.b = new SparseArray();
                }
                SparseArray sparseArray = dVar.b;
                if (keyEvent.getAction() == 1) {
                    int indexOfKey = sparseArray.indexOfKey(keyEvent.getKeyCode());
                    if (indexOfKey >= 0) {
                        weakReference = (WeakReference) sparseArray.valueAt(indexOfKey);
                        sparseArray.removeAt(indexOfKey);
                    }
                }
                if (weakReference == null) {
                    weakReference = (WeakReference) sparseArray.get(keyEvent.getKeyCode());
                }
                if (weakReference != null) {
                    view = (View) weakReference.get();
                    if (view == null || !view.isAttachedToWindow()) {
                        return true;
                    }
                    dVar.b(view, keyEvent);
                    return true;
                }
            }
        }
        return false;
    }

    /* JADX WARNING: Removed duplicated region for block: B:53:0x00bd  */
    /* JADX WARNING: Missing block: B:25:0x0060, code skipped:
            if (r0 == false) goto L_0x0063;
     */
    public static boolean b(b.i.k.e.a r7, android.view.View r8, android.view.Window.Callback r9, android.view.KeyEvent r10) {
        /*
        r0 = 0;
        if (r7 != 0) goto L_0x0004;
    L_0x0003:
        return r0;
    L_0x0004:
        r1 = android.os.Build.VERSION.SDK_INT;
        r2 = 28;
        if (r1 < r2) goto L_0x000f;
    L_0x000a:
        r7 = r7.e(r10);
        return r7;
    L_0x000f:
        r1 = r9 instanceof android.app.Activity;
        r2 = 0;
        r3 = 1;
        if (r1 == 0) goto L_0x0080;
    L_0x0015:
        r9 = (android.app.Activity) r9;
        r9.onUserInteraction();
        r7 = r9.getWindow();
        r8 = 8;
        r8 = r7.hasFeature(r8);
        if (r8 == 0) goto L_0x0063;
    L_0x0026:
        r8 = r9.getActionBar();
        r1 = r10.getKeyCode();
        r4 = 82;
        if (r1 != r4) goto L_0x0063;
    L_0x0032:
        if (r8 == 0) goto L_0x0063;
    L_0x0034:
        r1 = a;
        if (r1 != 0) goto L_0x004c;
    L_0x0038:
        r1 = r8.getClass();	 Catch:{ NoSuchMethodException -> 0x004a }
        r4 = "onMenuKeyEvent";
        r5 = new java.lang.Class[r3];	 Catch:{ NoSuchMethodException -> 0x004a }
        r6 = android.view.KeyEvent.class;
        r5[r0] = r6;	 Catch:{ NoSuchMethodException -> 0x004a }
        r1 = r1.getMethod(r4, r5);	 Catch:{ NoSuchMethodException -> 0x004a }
        b = r1;	 Catch:{ NoSuchMethodException -> 0x004a }
    L_0x004a:
        a = r3;
    L_0x004c:
        r1 = b;
        if (r1 == 0) goto L_0x0060;
    L_0x0050:
        r4 = new java.lang.Object[r3];	 Catch:{ IllegalAccessException | InvocationTargetException -> 0x005f, IllegalAccessException | InvocationTargetException -> 0x005f }
        r4[r0] = r10;	 Catch:{ IllegalAccessException | InvocationTargetException -> 0x005f, IllegalAccessException | InvocationTargetException -> 0x005f }
        r8 = r1.invoke(r8, r4);	 Catch:{ IllegalAccessException | InvocationTargetException -> 0x005f, IllegalAccessException | InvocationTargetException -> 0x005f }
        r8 = (java.lang.Boolean) r8;	 Catch:{ IllegalAccessException | InvocationTargetException -> 0x005f, IllegalAccessException | InvocationTargetException -> 0x005f }
        r0 = r8.booleanValue();	 Catch:{ IllegalAccessException | InvocationTargetException -> 0x005f, IllegalAccessException | InvocationTargetException -> 0x005f }
        goto L_0x0060;
    L_0x0060:
        if (r0 == 0) goto L_0x0063;
    L_0x0062:
        goto L_0x007f;
    L_0x0063:
        r8 = r7.superDispatchKeyEvent(r10);
        if (r8 == 0) goto L_0x006a;
    L_0x0069:
        goto L_0x007f;
    L_0x006a:
        r7 = r7.getDecorView();
        r8 = b.i.k.o.e(r7, r10);
        if (r8 == 0) goto L_0x0075;
    L_0x0074:
        goto L_0x007f;
    L_0x0075:
        if (r7 == 0) goto L_0x007b;
    L_0x0077:
        r2 = r7.getKeyDispatcherState();
    L_0x007b:
        r3 = r10.dispatch(r9, r2, r9);
    L_0x007f:
        return r3;
    L_0x0080:
        r1 = r9 instanceof android.app.Dialog;
        if (r1 == 0) goto L_0x00d3;
    L_0x0084:
        r9 = (android.app.Dialog) r9;
        r7 = c;
        if (r7 != 0) goto L_0x0099;
    L_0x008a:
        r7 = android.app.Dialog.class;
        r8 = "mOnKeyListener";
        r7 = r7.getDeclaredField(r8);	 Catch:{ NoSuchFieldException -> 0x0097 }
        d = r7;	 Catch:{ NoSuchFieldException -> 0x0097 }
        r7.setAccessible(r3);	 Catch:{ NoSuchFieldException -> 0x0097 }
    L_0x0097:
        c = r3;
    L_0x0099:
        r7 = d;
        if (r7 == 0) goto L_0x00a4;
    L_0x009d:
        r7 = r7.get(r9);	 Catch:{ IllegalAccessException -> 0x00a4 }
        r7 = (android.content.DialogInterface.OnKeyListener) r7;	 Catch:{ IllegalAccessException -> 0x00a4 }
        goto L_0x00a5;
    L_0x00a4:
        r7 = r2;
    L_0x00a5:
        if (r7 == 0) goto L_0x00b2;
    L_0x00a7:
        r8 = r10.getKeyCode();
        r7 = r7.onKey(r9, r8, r10);
        if (r7 == 0) goto L_0x00b2;
    L_0x00b1:
        goto L_0x00d2;
    L_0x00b2:
        r7 = r9.getWindow();
        r8 = r7.superDispatchKeyEvent(r10);
        if (r8 == 0) goto L_0x00bd;
    L_0x00bc:
        goto L_0x00d2;
    L_0x00bd:
        r7 = r7.getDecorView();
        r8 = b.i.k.o.e(r7, r10);
        if (r8 == 0) goto L_0x00c8;
    L_0x00c7:
        goto L_0x00d2;
    L_0x00c8:
        if (r7 == 0) goto L_0x00ce;
    L_0x00ca:
        r2 = r7.getKeyDispatcherState();
    L_0x00ce:
        r3 = r10.dispatch(r9, r2, r9);
    L_0x00d2:
        return r3;
    L_0x00d3:
        if (r8 == 0) goto L_0x00db;
    L_0x00d5:
        r8 = b.i.k.o.e(r8, r10);
        if (r8 != 0) goto L_0x00e1;
    L_0x00db:
        r7 = r7.e(r10);
        if (r7 == 0) goto L_0x00e2;
    L_0x00e1:
        r0 = 1;
    L_0x00e2:
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.i.k.e.b(b.i.k.e$a, android.view.View, android.view.Window$Callback, android.view.KeyEvent):boolean");
    }
}
